<?php
class mg_user extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('mmg_user');
	}
	
	function index()
	{
		$token = $this->session->userdata('token');
		if($token){
			$data['results'] = $this->mmg_user->getList();
			$this->load->view('mg_user/list',$data);
		}else{
			redirect('admin');
		}
	}
    
	function add(){
		$data['mode'] = "Create";
		$data['action'] = "save";
		$this->load->view('mg_user/form',$data);
	}
	
	function edit($id_menu){
		$data['mode'] = "Edit";
		$data['action'] = "update";
		$data['detail'] = $this->mmg_user->detail($id_menu);
		$this->load->view('mg_user/form',$data);
	}
    
	function save()
	{
		$id_user = $this->input->post('id_user');
		$nama_user = $this->input->post('nama_user');
		$email_user = $this->input->post('email_user');
		$chat_user = $this->input->post('chat_user');
		$pass_user = $this->input->post('pass_user');
		$enable_user = $this->input->post('enable_user');
		$submit = $this->input->post('submit');	
		if ($submit)
		{
			$this->mmg_user->setData($id_user,$nama_user,$email_user,$chat_user,$pass_user,$enable_user);
			$this->mmg_user->create();
			$this->session->set_flashdata('success', true);
			redirect('mg_user');
		}
	}
	
	function update()
	{
		$id_user = $this->input->post('id_user');
		$nama_user = $this->input->post('nama_user');
		$email_user = $this->input->post('email_user');
		$chat_user = $this->input->post('chat_user');
		$pass_user = $this->input->post('pass_user');
		$enable_user = $this->input->post('enable_user');
		$submit = $this->input->post('submit');	
		if ($submit)
		{
			$this->mmg_user->setData($id_user,$nama_user,$email_user,$chat_user,$pass_user,$enable_user);
			$this->mmg_user->update($id_user);
			$this->session->set_flashdata('success', true);
			redirect('mg_user');
		}
	}
	
	function delete($id_user)
	{
		if ($this->mmg_user->remove($id_user)){
			$this->session->set_flashdata('delete', true);
			redirect('mg_user','refresh');
		}	
	}	
}
?>